package com.zjbti.commonview;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.Toast;

public class CheckBoxActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {

    private TextView hobby;
    private CheckBox pingpong;
    private CheckBox baskball;
    private CheckBox yumaoqiu;
    private String hobbys;

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_check_box);
        pingpong = (CheckBox) findViewById(R.id.pingpong);
        baskball = (CheckBox) findViewById(R.id.baskball);
        yumaoqiu = (CheckBox) findViewById(R.id.yumaoqiu);
        pingpong.setOnCheckedChangeListener(this);
        baskball.setOnCheckedChangeListener(this);
        yumaoqiu.setOnCheckedChangeListener(this);
        hobby = (TextView) findViewById(R.id.hobby);
        hobbys=new String();
        Toast.makeText(CheckBoxActivity.this,"wifi已断开",Toast.LENGTH_SHORT).show();

    }
    public void onCheckedChanged(CompoundButton buttonView,boolean isChecked){
        String motion=buttonView.getText().toString();
        if(isChecked){
            if (!hobbys.contains(motion)){
                hobbys=hobbys+motion;
                hobby.setText(hobbys);

            }
        }else {
            if (hobbys.contains(motion)){
                hobbys=hobbys.replace(motion," ");
                hobby.setText(hobbys);
            }
        }
    }
}